<template>
  <div style="width:100vw;" class="teacher-box">
    <!-- <div class="record-header">
      <mt-header fixed title="徒弟详情">
        <router-link to="/myApprentice" slot="left">
          <mt-button class="back-butt" icon="back"></mt-button>
        </router-link>
      </mt-header>
    </div>-->
    <div class="teacher-head">
      <div class="teacher-card">
        <div class="flex-row teacher-card-top">
          <div>
            <p class="teacher-name">{{teacherList.username}}</p>
            <p class="teacher-ms">{{teacherList.deptName}}</p>
            <p class="teacher-mss">
              <span>{{teacherList.job}}</span>
              <span class="teacher-type">徒弟版</span>
            </p>
          </div>
          <div :style="`background-image:url(${teacherList.photo || require('@/assets/homePicture/userpicture.png')});`" class="teacher-picture">
            <!-- <img :src="teacherList.photo || require('@/assets/homePicture/userpicture.png')" alt /> -->
          </div>
        </div>
      </div>
      <div v-show="btn0==false" class="teacher-item flex-row">
        <div @click="studentAssessment" class="teacher-pj">
          <p style="font-size:22px;font-weight:800;color:#4787e4;" class="iconfont iconxueli"></p>
          <p>评价徒弟</p>
        </div>
        <div @click="unConcat" class="teacher-jc">
          <p
            style="font-size:22px;font-weight:800;color:#E6AC61;"
            class="iconfont iconjinyonghuiyuan"
          ></p>
          <p>解除关系</p>
        </div>
      </div>
    </div>
    <div class="deliver"></div>
    <div class="teacher-detail">
      <div style="padding-bottom:10px;" class="teacher-tips">个人资料</div>
      <div class="teacher-detail-item flex-row">
        <div class="teacher-partment">
          <span style="color:#4787e4;margin-right:5px;" class="iconfont iconweb-icon-"></span>
          <span>部门</span>
        </div>
        <div class="teacher-partment-name">{{teacherList.deptName}}</div>
      </div>
      <div class="teacher-detail-item flex-row">
        <div class="teacher-partment">
          <span style="color:#4787e4;margin-right:5px;" class="iconfont iconqiwangzhiwei"></span>
          <span>岗位</span>
        </div>
        <div class="teacher-partment-name">{{teacherList.job}}</div>
      </div>
      <div class="teacher-detail-item flex-row">
        <div class="teacher-partment">
          <span style="color:#4787e4;margin-right:5px;" class="iconfont iconxueli"></span>
          <span>学历</span>
        </div>
        <div class="teacher-partment-name">{{teacherList.edu}}</div>
      </div>
      <div class="teacher-detail-item flex-row">
        <div class="teacher-partment">
          <span style="color:#4787e4;margin-right:5px;" class="iconfont iconlingdaitie2"></span>
          <span>专业</span>
        </div>
        <div class="teacher-partment-name">{{teacherList.major}}</div>
      </div>
      <div style="margin-bottom:0;" class="teacher-detail-item flex-row">
        <div class="teacher-partment">
          <span style="color:#4787e4;margin-right:5px;" class="iconfont iconxingming"></span>
          <span>职称</span>
        </div>
        <div class="teacher-partment-name">{{teacherList.jobTitle}}</div>
      </div>
      <div v-if="btn0" class="btn-group flex-row">
        <mt-button @click.native="confirm(2)" type="default" size="normal">驳回</mt-button>
        <mt-button @click.native="confirm(1)" type="primary" size="normal">通过</mt-button>
      </div>
    </div>
  </div>
</template>
<script>
import { MessageBox, Toast } from "mint-ui";
import { setText } from "../../untils/ddnavigate";
export default {
  data() {
    return {
      teacherList: {},
      btn0: false,
      id: ""
    };
  },
  mounted() {
    let that = this;
    let { id, statusNum, cancleFlag } = this.$route.query;
    let params = {
      id
    };
    this.id = id;
    if (statusNum == 0) {
      this.btn0 = true;
    }
    if (cancleFlag == 2) {
      MessageBox.confirm("", "", {
        message: "您的徒弟向您发起了师徒关系解除",
        title: "提示",
        confirmButtonText: "确认",
        cancelButtonText: "驳回"
      })
        .then(status => {
          let params = {
            stuId: that.teacherList.id
          };
          that.$post("sureCancle", params).then(res => {
            if (res.success) {
              Toast({
                message: "解除成功",
                duration: 2000
              });
              setTimeout(() => {
                that.$router.push({ path: "/StudyCenter" });
              }, 2000);
            }
          });
        })
        .catch(status => {
          let params = {
            stuId: that.teacherList.id
          };
          that.$post("noSureCancle", params).then(res => {
            if (res.success) {
              Toast({
                message: "已驳回",
                duration: 2000
              });
              setTimeout(() => {
                that.$router.push({ path: "/StudyCenter" });
              }, 2000);
            }
          });
        });
    }
    this.$get("qryUserInfoById", params).then(res => {
      if (res.success) {
        for (var key in res.data) {
          if (key == "edu") {
            if (res.data[key] == 0) {
              res.data[key] = "大专";
            } else if (res.data[key] == 1) {
              res.data[key] = "本科";
            } else if (res.data[key] == 2) {
              res.data[key] = "硕士";
            } else if (res.data[key] == 3) {
              res.data[key] = "博士";
            }
          }
        }
        this.teacherList = res.data;
      }
    });
    // 设置标题文字
    setText("徒弟详情");
  },
  methods: {
    // goComment() {
    //   this.$router.push({ path: "/commentTeacher" });
    // },
    studentAssessment(){
      let id = this.teacherList.id;
      this.$router.push({
        path:'/StudentAssessment',
        query:{
          id
        }
      })
    },
    unConcat() {
      let that = this;
      let stuId = that.teacherList.id;
      let params = {
        stuId,
        cancleFlag: 1
      };
      MessageBox.confirm("确定要解除师徒关系吗？")
        .then(status => {
          that.$post("cancelRelationship", params).then(res => {
            if (res.success) {
              Toast({
                message: "已发出解除申请",
                iconClass: "mint-toast-icon mintui mintui-success",
                duration: 2000
              });
              setTimeout(() => {
                that.$router.push({ path: "/studyCenter" });
              }, 2000);
            }
          });
        })
        .catch(status => {
          console.log(status);
        });
    },
    confirm(type) {
      let params = {
        stuId: this.id,
        status: type
      };
      this.$get("dealApplay", params).then(res => {
        if (res.success) {
          Toast({
            message: "操作成功",
            iconClass: "mint-toast-icon mintui mintui-success",
            duration: 2000
          });
          this.$router.go(-1);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
@import url("~@/pagecss/myteacher.less");
.btn-group {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 23/75rem 30/75rem;
  background-color: #ffffff;
}
.btn-group button {
  flex: 1 0 auto;
}
.mint-button--default {
  margin-right: 66/75rem;
}
</style>